<template slot-scope="scope">
  <div>
    <el-checkbox :indeterminate="isIndeterminateRepair" v-model="checkAllRepair" @change="handleRepairCheckAllChange">旧件回运仓库</el-checkbox>
    <div style="margin:0px 0px 0px 20px;width:20px;">
      <el-checkbox-group v-model="checkedListRepairRepair" @change="handleCheckedCitiesChangeRepair">
        <el-checkbox v-for="repairs in sitesRepairRepair" :label="repairs.whCode" :key="repairs.whCode" :value="repairs.whCode">
          {{repairs.whName}}
        </el-checkbox>
      </el-checkbox-group>
    </div>
  </div>
</template>


<script>
  import { getAllWarehouse } from '@/api/common/auth/roleManage';

  export default {
    name: "Todo",
    props:['userPermissionData'],
    data() {
      return {
        checkAllRepair: false,
        checkedListRepairRepair: [],
        loading: false,
        isIndeterminateRepair: false,
        sitesRepairRepair: [],
        roleId: '',
      }
    },
    created() {
      this.loadData()
    },
    methods: {
      async loadData() {
        this.loading = true;
        const getMaintainRes = await getAllWarehouse()
        this.loading = false
        console.log(getMaintainRes, '仓库数据');
        // console.log(getMaintainRes.data,"getMaintainRes.data")
        if(getMaintainRes.resultCode === 200&&getMaintainRes.data&&getMaintainRes.data.length>0) {
          this.sitesRepairRepair = _.cloneDeep(getMaintainRes.data);
        }

        console.log(this.userPermissionData,"仓库")
        if(this.userPermissionData.claimWarehouse){
          let checkList = this.userPermissionData.claimWarehouse.split(",")
          console.log(checkList, 'checkList');
          checkList.forEach(x=>{
            this.checkedListRepairRepair.push(x)
          })
          if(this.checkedListRepairRepair.length == this.sitesRepairRepair.length){
            this.checkAllRepair=true
          }
        }
      },
      handleRepairCheckAllChange(val) {
        const checkedListRepairRepair = [];
        if (val) {
          for (var i = 0; i < this.sitesRepairRepair.length; i++) {
            checkedListRepairRepair.push(this.sitesRepairRepair[i].whCode);
          }
        }
        this.checkedListRepairRepair = checkedListRepairRepair;
        this.isIndeterminateRepair = false;
      },
      handleCheckedCitiesChangeRepair(value) {
        let checkedCount = value.length;
        this.checkAllRepair = checkedCount === this.sitesRepairRepair.length;
        this.isIndeterminateRepair = checkedCount > 0 && checkedCount < this.sitesRepairRepair.length;
      },
      getData() {
        return [...this.checkedListRepairRepair]
      }
    }
  }

</script>

<style scoped>
  .el-checkbox+.el-checkbox {
    margin-left: 0px;
  }
  .el-checkbox {
    margin-right: 25px;
  }

</style>
